#include "stdafx.h"
#include "NFG.h"
#include "stdio.h"

void LoadNFG(char *szFileName, GLuint &numVertices, GLuint &numIndices, Vertex *&vertexData, GLuint *&indices)
{
	//Dome
	register int i;
	int idx;

	FILE *pf;
	if(fopen_s(&pf, szFileName, "rb") != 0)
		return;
	//Read Vertices Position
	fscanf(pf, "NrVertices: %d\n", &numVertices);
	vertexData = new Vertex[numVertices];
	for(i=0; i<numVertices; i++)
	{
		fscanf(pf, "%d. pos:[%f, %f, %f]; norm:[%f, %f, %f]; binorm:[%f, %f, %f]; tgt:[%f, %f, %f]; uv:[%f, %f];\n",
			&idx,
			&(vertexData[i].Pos.x), &(vertexData[i].Pos.y), &(vertexData[i].Pos.z),
			&(vertexData[i].Norm.x), &(vertexData[i].Norm.y), &(vertexData[i].Norm.z),
			&(vertexData[i].BiNorm.x), &(vertexData[i].BiNorm.y), &(vertexData[i].BiNorm.z),
			&(vertexData[i].TGT.x), &(vertexData[i].TGT.y), &(vertexData[i].TGT.z),
			&(vertexData[i].TexCood.x), &(vertexData[i].TexCood.y));
	}

	//Read Indices Of Vertex
	fscanf(pf, "NrIndices: %d\n", &numIndices);
	indices = new GLuint[numIndices];
	for(int i=0; i<numIndices; i++)
	{
		fscanf(pf, "%d. %d, %d, %d\n", &idx, &indices[i], &indices[i+1], &indices[i+2]);
		i += 2;
	}

	fclose(pf);
}